﻿using BLL;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BONGDA
{
    public partial class frmOutHome : Form
    {
        const int speed = 18;
        int count = 0;
        PictureBox[] listPicture;
        Panel panelShow;
        int stateSlide = 0;
        // 0 stop
        // 1 left
        // 2 right
        public frmOutHome()
        {
            InitializeComponent();
            //panel
            panelShow = new Panel();
            panelShow.Width = 616;
            panelShow.Height = 154;
            panelShow.Location = new System.Drawing.Point(130, 70);
            panelShow.Anchor = AnchorStyles.Top | AnchorStyles.Left;
            panelShow.BackColor = Color.White;
            panelShow.Visible = true;
            this.Controls.Add(panelShow);
            //Picture
            listPicture = new PictureBox[20];
            string[] images = Directory.GetFiles(@"logo", "*.png");
            for (int i = 0; i < 20; i++)
            {
                Image image = Image.FromFile(images[i]);
                listPicture[i] = new PictureBox();
                listPicture[i].Image = image;
                listPicture[i].Location = new System.Drawing.Point(-616 + i * (154), 0);
                listPicture[i].Name = "pictureBox" + i;
                listPicture[i].Size = new System.Drawing.Size(154, 154);
                listPicture[i].SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
                listPicture[i].BackColor = Color.Transparent;
                listPicture[i].Visible = true;
                //picture.TabIndex = 0;
                //picture.TabStop = false;
                panelShow.Controls.Add(listPicture[i]);
            }
            rdb2.Checked = true;
        }

        private void testFrom_Load(object sender, EventArgs e)
        {
            moveTimer.Interval = 1;
            moveTimer.Tick += new EventHandler(moveTimer_Tick);
            moveTimer.Start();
        }

        private void btnLeft_Click(object sender, EventArgs e)
        {
            if (stateSlide == 0)
            {
                stateSlide = 1;
                count = 0;
                if (rdb1.Checked)
                {
                    rdb2.Checked = true;
                }
                else if (rdb2.Checked)
                {
                    rdb3.Checked = true;
                }
                else if (rdb3.Checked)
                {
                    rdb4.Checked = true;
                }
                else if (rdb4.Checked)
                {
                    rdb5.Checked = true;
                }
                else if (rdb5.Checked)
                {
                    rdb1.Checked = true;
                }
            }
        }

        private void btnRight_Click(object sender, EventArgs e)
        {
            if (stateSlide == 0)
            {
                stateSlide = 2;
                count = 0;
                if (rdb1.Checked)
                {
                    rdb5.Checked = true;
                }
                else if (rdb2.Checked)
                {
                    rdb1.Checked = true;
                }
                else if (rdb3.Checked)
                {
                    rdb2.Checked = true;
                }
                else if (rdb4.Checked)
                {
                    rdb3.Checked = true;
                }
                else if (rdb5.Checked)
                {
                    rdb4.Checked = true;
                }
            }            
        }

        private void moveTimer_Tick(object sender, EventArgs e)
        {            
            switch (stateSlide)
            {
                case 0:
                    break;
                case 1:
                    int tile = listPicture[0].Width;
                    for (int i = 0; i < 20; i++)
                    {
                        listPicture[i].Left -= speed;
                        if (listPicture[i].Left <= -900)
                        {
                            listPicture[i].Left = 2700;
                        }
                    }
                    count++;
                    if (count == 40)
                    {
                        count = 0;
                        stateSlide = 0;
                    }
                    break;
                case 2:
                    for (int i = 0; i < 20; i++)
                    {
                        listPicture[i].Left += speed;
                        if (listPicture[i].Left >= 2880)
                        {
                            listPicture[i].Left = -720;
                        }
                    }
                    count++;
                    if (count == 40)
                    {
                        count = 0;
                        stateSlide = 0;
                    }
                    break;
                default:
                    break;
            }
        }

        private void btnNewL_Click(object sender, EventArgs e)
        {
            DialogResult dl;
            dl = MessageBox.Show("Toàn bộ dữ liệu về giải đấu sẻ bị mất. Bạn có muốn tiếp tục?",
                                "Thông báo",
                                MessageBoxButtons.OKCancel,
                                MessageBoxIcon.Warning);
            if (dl == DialogResult.OK)
            {
                CTTranDau_BLL.Delete();
                LichThiDau_BLL.Delete();
                Application.Exit();
            }
        }
    }
}
